package fm.dongman.animefm.view.adapter

import android.app.Fragment
import android.app.FragmentManager
import android.support.v13.app.FragmentPagerAdapter
import android.util.Log

import fm.dongman.animefm.view.fragment.BaseFragment

/**
 * created by alex 2017.10.19
 */
class SearchResultAdapter(fm: FragmentManager, private val mTitles: Array<String>,
                          private val mFragmentList: Array<BaseFragment>,
                          private val mKey: ArrayList<String>)
    : FragmentPagerAdapter(fm) {

    override fun getItem(position: Int): Fragment = mFragmentList[position]

    override fun getCount(): Int = mFragmentList.size

    override fun getPageTitle(position: Int): CharSequence = mTitles[position]

    override fun notifyDataSetChanged() {
        super.notifyDataSetChanged()
        mFragmentList.forEach { setParamKey(it) }
    }

    /**
     * 关键字改变
     * @param baseFragment 位置
     */
    private fun setParamKey(baseFragment: BaseFragment) {
        baseFragment.setNewParam(mKey[0])
        Log.d(javaClass.simpleName, "搜索关键字：" + mKey)
    }
}

